package com.gao.sqlserverspeedy.controller;

import com.gao.sqlserverspeedy.config.BaseService;
import com.gao.sqlserverspeedy.entity.R;
import com.gao.sqlserverspeedy.entity.SqlBase;
import com.gao.sqlserverspeedy.server.ISqlTableService;
import com.gao.sqlserverspeedy.server.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sqltable")
public class SqlTableController {
    @Autowired
    private ISqlTableService sqlTableService;
    @Autowired
    private BaseService baseService;

    @RequestMapping("/list")
    public R list() {
        return R.ok(sqlTableService.selectTables());
    }

    @RequestMapping("/info/{tableName}")
    public R info(@PathVariable String tableName) {
        return R.ok(sqlTableService.selectTableInfo(tableName));
    }

    //当前数据源
    @RequestMapping("/danqiansql")
    public R danqiansql() {
        return R.ok(baseService.getSQLBaes());
    }

    //切换数据源
    @PostMapping("/qiehuansql")
    public R qiehuansql(@RequestBody SqlBase sqlBase) {
        return R.ok(baseService.changeDataSource(sqlBase));
    }
}
